]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
Switch string formatting to the one inside gjs
authorJasper St. Pierre <jstpierre@mecheye.net>
Fri, 4 May 2012 21:23:08 +0000 (17:23 -0400)
committerJasper St. Pierre <jstpierre@mecheye.net>
Thu, 24 May 2012 19:38:44 +0000 (15:38 -0400)
https://bugzilla.gnome.org/show_bug.cgi?id=675479

js/Makefile.am
js/extensionPrefs/main.js
js/misc/format.js [deleted file]
js/ui/environment.js
src/shell-js.c
src/shell-js.h

index 6b055365e4a841a46fafa05ded09d1e6c2e9c408..ea66c3e32e0afef265b7f635745cde22fc7d99e3 100644 (file)
@@ -28,7 +28,6 @@ nobase_dist_js_DATA =         \
        misc/config.js          \
        misc/extensionUtils.js  \
        misc/fileUtils.js       \
-       misc/format.js          \
        misc/gnomeSession.js    \
        misc/history.js         \
        misc/jsParse.js         \
index 59bf6cb5353f5d1388d4c8ecb8ff749026c969e2..c924af5906c4363ab191580f79f34db2eb48d046 100644 (file)
@@ -6,11 +6,11 @@ const GObject = imports.gi.GObject;
 const Gio = imports.gi.Gio;
 const Gtk = imports.gi.Gtk;
 const Pango = imports.gi.Pango;
+const Format = imports.format;
 
 const _ = Gettext.gettext;
 
 const Config = imports.misc.config;
-const Format = imports.misc.format;
 const ExtensionUtils = imports.misc.extensionUtils;
 
 
diff --git a/js/misc/format.js b/js/misc/format.js
deleted file mode 100644 (file)
index c30a1ba..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
-
-const ShellJS = imports.gi.ShellJS;
-
-/*
- * This function is intended to extend the String object and provide
- * an String.format API for string formatting.
- * It has to be set up using String.prototype.format = Format.format;
- * Usage:
- * "somestring %s %d".format('hello', 5);
- * It supports %s, %d, %x and %f, for %f it also support precisions like
- * "%.2f".format(1.526). All specifiers can be prefixed with a minimum
- * field width, e.g. "%5s".format("foo"). Unless the width is prefixed
- * with '0', the formatted string will be padded with spaces.
- */
-
-function format() {
-    let str = this;
-    let i = 0;
-    let args = arguments;
-
-    return str.replace(/%(I+)?([0-9]+)?(?:\.([0-9]+))?(.)/g, function (str, flagsGroup, widthGroup, precisionGroup, genericGroup) {
-
-                    if (precisionGroup != '' && genericGroup != 'f')
-                        throw new Error("Precision can only be specified for 'f'");
-
-                    let hasAlternativeIntFlag = (flagsGroup.indexOf('I') != -1);
-
-                    if (hasAlternativeIntFlag && genericGroup != 'd')
-                        throw new Error("Alternative output digits can only be specfied for 'd'");
-
-                    let fillChar = (widthGroup[0] == '0') ? '0' : ' ';
-                    let width = parseInt(widthGroup, 10) || 0;
-
-                    function fillWidth(s, c, w) {
-                        let fill = '';
-                        for (let i = 0; i < w; i++)
-                            fill += c;
-                        return fill.substr(s.length) + s;
-                    }
-
-                    let s = '';
-                    switch (genericGroup) {
-                        case '%':
-                            return '%';
-                            break;
-                        case 's':
-                            s = args[i++].toString();
-                            break;
-                        case 'd':
-                            let intV = parseInt(args[i++]);
-                            if (hasAlternativeIntFlag)
-                                s = ShellJS.format_int_alternative_output(intV);
-                            else
-                                s = intV.toString();
-                            break;
-                        case 'x':
-                            s = parseInt(args[i++]).toString(16);
-                            break;
-                        case 'f':
-                            if (precisionGroup == '')
-                                s = parseFloat(args[i++]).toString();
-                            else
-                                s = parseFloat(args[i++]).toFixed(parseInt(precisionGroup));
-                            break;
-                        default:
-                            throw new Error('Unsupported conversion character %' + genericGroup);
-                    }
-                    return fillWidth(s, fillChar, width);
-                });
-}
index fc3992ae2fae49497e681cb955dac9fba046adf3..aa7a4bd071f5584f4c335caf3e068f294a291dc4 100644 (file)
@@ -90,7 +90,7 @@ function init() {
     }
 
     // OK, now things are initialized enough that we can import shell JS
-    const Format = imports.misc.format;
+    const Format = imports.format;
     const Tweener = imports.ui.tweener;
 
     Tweener.init();
index 6657b48799e7386e4a89ad2aa4732b65a83da242..8267fdc98b2f9fcf5ded6e4541487319956f8484 100644 (file)
@@ -79,15 +79,3 @@ shell_js_add_extension_importer (const char  *target_object_script,
   JS_EndRequest (context);
   return ret;
 }
-
-/**
- * shell_js_format_int_alternative_output:
- * @intval:
- *
- * Returns: (transfer full):
- */
-gchar *
-shell_js_format_int_alternative_output (gint intval)
-{
-  return g_strdup_printf ("%Id", intval);
-}
index fd8530480b7828179809477c933f8ab9626d0f7e..26cbf4d82d9f2ece2b00d212715e95e38037d530 100644 (file)
@@ -11,8 +11,6 @@ gboolean shell_js_add_extension_importer (const char   *target_object_script,
                                           const char   *directory,
                                           GError      **error);
 
-gchar   *shell_js_format_int_alternative_output (gint intval);
-
 G_BEGIN_DECLS
 
 #endif /* __SHELL_JS_H__ */